package com.yss.reportworld.controller;

import java.util.List;
import java.util.Date;
import javax.servlet.http.HttpServletResponse;

import com.yss.common.core.utils.StringUtils;
import com.yss.common.core.utils.easyexecl.EasyExeclUtil;
import com.yss.common.core.utils.uuid.IdUtils;
import com.yss.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yss.common.logger.annotation.Log;
import com.yss.common.logger.enums.BusinessType;
import com.yss.common.security.annotation.RequiresPermissions;
import com.yss.reportworld.domain.TableDetailStandardCheck;
import com.yss.reportworld.service.ITableDetailStandardCheckService;
import com.yss.common.core.web.controller.BaseController;
import com.yss.common.core.web.domain.AjaxResult;
import com.yss.common.core.web.page.TableDataInfo;

/**
 * 字段校验规则Controller
 *
 * @author yss
 * @date 2023-04-07
 */
@RestController
@RequestMapping("/tableDetailStandardCheck")
public class TableDetailStandardCheckController extends BaseController {
    @Autowired
    private ITableDetailStandardCheckService tableDetailStandardCheckService;

    /**
     * 查询字段校验规则列表
     */
    @RequiresPermissions("reportworld:tableDetailStandardCheck:list")
    @GetMapping("/list")
    public TableDataInfo list(TableDetailStandardCheck tableDetailStandardCheck) {
        startPage();
        List<TableDetailStandardCheck> list = tableDetailStandardCheckService.selectTableDetailStandardCheckList(tableDetailStandardCheck);
        return getDataTable(list);
    }

    /**
     * 导出字段校验规则列表
     */
    @RequiresPermissions("reportworld:tableDetailStandardCheck:export")
    @Log(title = "字段校验规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TableDetailStandardCheck tableDetailStandardCheck) {
        List<TableDetailStandardCheck> list = tableDetailStandardCheckService.selectTableDetailStandardCheckList(tableDetailStandardCheck);
        EasyExeclUtil.export(response, list, TableDetailStandardCheck.class);
    }

    /**
     * 获取字段校验规则详细信息
     */
    @RequiresPermissions("reportworld:tableDetailStandardCheck:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(tableDetailStandardCheckService.getById(id));
    }

    /**
     * 新增字段校验规则
     */
    @RequiresPermissions("reportworld:tableDetailStandardCheck:add")
    @Log(title = "字段校验规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Validated TableDetailStandardCheck tableDetailStandardCheck) {
        tableDetailStandardCheck.setId(IdUtils.fastSimpleUUID());
        tableDetailStandardCheck.setCreateBy(SecurityUtils.getUsername());
        tableDetailStandardCheck.setCreateTime(new Date());
        return toAjax(tableDetailStandardCheckService.save(tableDetailStandardCheck));
    }

    /**
     * 修改字段校验规则
     */
    @RequiresPermissions("reportworld:tableDetailStandardCheck:edit")
    @Log(title = "字段校验规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody @Validated TableDetailStandardCheck tableDetailStandardCheck) {
        tableDetailStandardCheck.setUpdateTime(new Date());
        tableDetailStandardCheck.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(tableDetailStandardCheckService.updateById(tableDetailStandardCheck));
    }

    /**
     * 删除字段校验规则
     */
    @RequiresPermissions("reportworld:tableDetailStandardCheck:remove")
    @Log(title = "字段校验规则", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<String> ids) {
        return toAjax(tableDetailStandardCheckService.removeByIds(ids));
    }
}
